package com.example.myapplication2;

import android.content.ComponentName;
import android.content.Intent;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class StaticBroadcastActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_static_broadcast);
        findViewById(R.id.StaticBroadcastVibration).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.StaticBroadcastVibration:
                String fullName="com.example.myapplication2.StaticReceiver";
                //创建StaticBroadcast意图的对象
                Intent intent = new Intent("StaticBroadcast");
                //发送广播时,设置接收者的完整路径
                ComponentName componentName = new ComponentName(this, fullName);
                //设置意图的组件信息
                intent.setComponent(componentName);
                //发送广播
                sendBroadcast(intent);
                System.out.println("发送");
                break;
        }
    }
}